package com.nativetalk.common.getui;

import com.gexin.rp.sdk.base.IPushResult;
import com.gexin.rp.sdk.base.impl.SingleMessage;
import com.gexin.rp.sdk.base.payload.APNPayload;
import com.gexin.rp.sdk.http.IGtPush;
import com.gexin.rp.sdk.template.TransmissionTemplate;
import com.nativetalk.common.Constants;
import org.apache.log4j.Logger;

/**
 * Created by wangzheng on 2017/5/4.
 */
public class IosCommentTeacher {
    private static Logger logger = Logger.getLogger(IosTeacherGetui.class);
    static String appId = Constants.teacher_appId;
    static String appKey = Constants.teacher_appKey;
    static String masterSecret = Constants.teacher_masterSecret;
    static String url = Constants.getui_url;

    public static void apnpush(String title,String body,String devicetoken,int reserve_id
            ,String memb_name,String memb_head_portrait,String channel,String tea_head_portrait,String tea_name,String cou_english_name)  {
        TransmissionTemplate template = new TransmissionTemplate();
        template.setAppId(appId);
        template.setAppkey(appKey);
        template.setTransmissionType(2);        //应用启动类型，1：强制应用启动 2：等待应用启动



        //APN高级推送
        APNPayload apnpayload = new APNPayload();
        APNPayload.DictionaryAlertMsg alertMsg = new APNPayload.DictionaryAlertMsg();
        alertMsg.setBody(body);
        //IOS8.2支持字段
        alertMsg.setTitle(title);

        apnpayload.setAlertMsg(alertMsg);
        apnpayload.setContentAvailable(30);//透传数据
        apnpayload.addCustomMsg("memb_name",memb_name);
        apnpayload.addCustomMsg("reserve_id",reserve_id);
        apnpayload.addCustomMsg("memb_head_portrait",memb_head_portrait);
        apnpayload.addCustomMsg("channel",channel);
        apnpayload.addCustomMsg("tea_head_portrait",tea_head_portrait);
        apnpayload.addCustomMsg("tea_name",tea_name);
        apnpayload.addCustomMsg("cou_english_name",cou_english_name);
        template.setAPNInfo(apnpayload);

        IGtPush push = new IGtPush(url, appKey, masterSecret);


        SingleMessage message = new SingleMessage();
        message.setData(template);

        IPushResult pushResult = push.pushAPNMessageToSingle(appId,devicetoken,message);
        logger.info(pushResult.getResponse());

    }
}
